home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 February / CMCD0205.ISO / Software / Freeware / Programare / bluej / bluejsetup-203.exe / {app} / examples / people2 / Person.java < prev    next >
Text File  |  2004-12-19  |  2KB  |  81 lines

  1. /**
  2.  * A person class for a simple BlueJ demo program. Person is used as
  3.  * an abstract superclass of more specific person classes.
  4.  *
  5.  * @author  Michael Kolling
  6.  * @version 1.0, January 1999
  7.  */
  8.  
  9. abstract class Person
  10. {
  11.     private String name;
  12.     private int yearOfBirth;
  13.     private Address address;
  14.  
  15.     /**
  16.      * Create a person with given name and age.
  17.      */
  18.     Person(String name, int yearOfBirth)
  19.     {
  20.         this.name = name;
  21.         this.yearOfBirth = yearOfBirth;
  22.     }
  23.  
  24.     /**
  25.      * Set a new name for this person.
  26.      */
  27.     public void setName(String newName)
  28.     {
  29.         name = newName;
  30.     }
  31.  
  32.     /**
  33.      * Return the name of this person.
  34.      */
  35.     public String getName()
  36.     {
  37.         return name;
  38.     }
  39.     
  40.     /**
  41.      * Set a new birth year for this person.
  42.      */
  43.     public void setYearOfBirth(int newYearOfBirth)
  44.     {
  45.         yearOfBirth = newYearOfBirth;
  46.     }
  47.  
  48.     /**
  49.      * Return the birth year of this person.
  50.      */
  51.     public int getYearOfBirth()
  52.     {
  53.         return yearOfBirth;
  54.     }
  55.  
  56.     /**
  57.      * Set a new address for this person.
  58.      */
  59.     public void setAddress(String street, String town, String postCode)
  60.     {
  61.         address = new Address(street, town, postCode);
  62.     }
  63.  
  64.     /**
  65.      * Return the address of this person.
  66.      */
  67.     public Address getAddress()
  68.     {
  69.         return address;
  70.     }
  71.  
  72.     /**
  73.      * Return a string representation of this object.
  74.      */
  75.     public String toString()    // redefined from "Object"
  76.     {
  77.         return "Name: " + name + "\n" +
  78.                "Year of birth: " + yearOfBirth + "\n";
  79.     }
  80. }
  81.